window.addEventListener('load', function () {
    let regtel = /^(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;

    let tel = document.querySelector('.tel');
    let col = document.querySelector('.col');
    let cha = document.querySelector('.cha');
    let duanxin = document.querySelector('.duanxin');
    let yanzhen = document.querySelector('.yanzheng');
    let ca = document.querySelector('.ca');
    let pa = document.querySelector('.pa');
    let pas = document.querySelector('.pas');
    let mima = document.querySelector('.mima');
    let qu = document.querySelector('.qu');
    let queren = document.querySelector('.queren');
    let que = document.querySelector('.que');

    tel.addEventListener('blur', function () {
        let telVal = tel.value.trim();
        if (telVal == '') {
            col.className = '';
            cha.style.display = 'none';
            col.innerHTML = '';
        } else if (regtel.test(telVal)) {
            col.style.color = '#3cba3c';
            col.innerHTML = '手机号输入正确';
            cha.style.display = 'none';
        } else {
            col.innerHTML = '手机号输入错误';
            cha.style.display = 'inline-block';
            col.style.color = '#e12d2c';
        }
    });

    // 短信验证码判断
    let regDuan = /^[a-zA-Z0-9]{4}$/;
    duanxin.addEventListener('blur', function () {
        let duanxinVal = duanxin.value.trim();
        if (duanxinVal == '') {
            yanzhen.className = '';
            ca.style.display = 'none';
            yanzhen.innerHTML = '';
        } else if (regDuan.test(duanxinVal)) {
            yanzhen.style.color = '#3cba3c';
            yanzhen.innerHTML = '验证码输入正确';
            ca.style.display = 'none';
        } else {
            yanzhen.innerHTML = '验证码输入错误';
            ca.style.display = 'inline-block';
            yanzhen.style.color = '#e12d2c';
        }
    })

    // 密码验证
    let regMima = /^[\W|_a-zA-Z0-9]{6,16}$/
    mima.addEventListener('blur', function () {
        let mimaVal = mima.value.trim();
        if (mimaVal == '') {
            pas.className = '';
            pa.style.display = 'none';
            pas.innerHTML = '';
        } else if (regMima.test(mimaVal)) {
            pas.style.color = '#3cba3c';
            pas.innerHTML = '密码输入正确';
            pa.style.display = 'none';
        } else {
            pas.innerHTML = '密码长度6-16位';
            pa.style.display = 'inline-block';
            pas.style.color = '#e12d2c';
        }
        // 判断输入密码是否一致
        queren.addEventListener('blur', function () {
            let querenVal = queren.value.trim();
            if (querenVal == '') {
                qu.style.display = 'none';
                que.innerHTML = '';
            } else if (querenVal == mimaVal) {
                que.style.color = '#3cba3c';
                que.innerHTML = '密码输入正确';
                qu.style.display = 'none';
            } else {
                que.innerHTML = '密码不一致,请重新输入';
                qu.style.display = 'inline-block';
                que.style.color = '#e12d2c';
            }
        })
    })
    // 密码强度验证

    // 输入事件：只有你输入了才触发
    let qiangdu = document.querySelector('.qiangdu');

    document.querySelector('.mima').onkeyup = function () {

        let tip = document.querySelector('.tip')
        // 找到等级
        let level = document.querySelector('.level')
        // 拿到输入内容
        let val = mima.value
        // 分数从0开始
        let score = 0

        if (val < 6) {
            tip.innerHTML = '密码长度不足小于6';
            level.className = 'level'
        } else {
            if (/\d/.test(val)) {
                score++;
            }
            // 有没有字母
            if (/[a-zA-Z]/.test(val)) {
                score++;
            }
            // 有没有符号
            if (/\W|_/.test(val)) {
                score++
            }

            level.className = `level level${score}`
        }

        // 根据分数做不同的文字
        switch (score) {
            case 1:
                tip.innerHTML = '弱';
                break;
            case 2:
                tip.innerHTML = '中';
                break;
            case 3:
                tip.innerHTML = '强';
                break;
        }
    }
})